package cube.utils.db.query;

import java.util.Date;

import cube.utils.TimeUtil;

/**
 * 条件转换辅助工具
 * 
 * @author abiao
 */
public class ConditionUtil {

    /**
     * 转换集合条件(in 或 not in)
     */
    public static <T> String convert(T... set) {
        StringBuffer sb = new StringBuffer();
        sb.append("( ");
        for (int i = 0; i < set.length - 1; i++) {
            sb.append(set[i] + ", ");
        }
        if (set.length > 0) {
            sb.append(set[set.length - 1] + " ");
        }
        sb.append(")");
        return sb.toString();
    }

    /**
     * 转换日期条件
     */
    public static String convert(Date d) {
        String date = TimeUtil.getTime(d, "yyyy-MM-dd HH:mm:ss.SSS");
        return "to_timestamp('" + date + "', 'yyyy-mm-dd hh24:mi:ss.ff3')";
    }
}
